type Toptions_Pselect = Toptions_CDVP & {
};

@ACdisabled
@ACreadonly
@AConchange
@ACcontrols
@ACname
@ACdata
class Pselect extends _CDVP_<Toptions_Pselect> {
    // ====================================================== 当前控件特殊实现 ====================================================== //
    // @ts-ignore Property 'select' has no initializer and is not definitely assigned in the constructor.ts(2564)
    private ele_select: KHTMLElement;

    // ====================================================== 初始化参数 ====================================================== //
    static defaultOptions: Toptions_Pselect = {
    };
    protected override options_default(): Toptions_Pselect {
        return Pselect.defaultOptions;
    }
    protected override options_handlers(): Toptions_handlers<Toptions_Pselect> {
        return {
        };
    }
    protected override overloading_mapping(mapping: Toption_key_to_types_mapping<Toptions_Pselect>): Toverloading_mapping<Toptions_Pselect> {
        return [
        ];
    }
    protected override options_checker(options: Toptions_Pselect): void {
    }

    // ====================================================== 创建实例对象 ====================================================== //
    protected override initializer(): void {
        this.ele_select = this.ele.createElement('select').addClass(_CP_.CLASSES.INPUTER);
        if (this.options.multiple === true) {
            (this.ele_select.ele() as HTMLSelectElement).multiple = true;
            (this.ele_select.ele() as HTMLSelectElement).size = 3;
        }
    }
    protected override afterInitializer(): void {
    }

    // ====================================================== 创建数据值控件实例对象 ====================================================== //
    protected override item_render(dataI: Toptions_DATA$dataI, text: string, value: any) {
        // 选项
        const ele_option = this.ele_select.createElement('option').setAttr('textContent', text);

        return ele_option.ele()!;
    }
    public override getValue(): any {
        const result: any = [];
        this.items.forEach(ele_item => {
            if ((ele_item as HTMLOptionElement).selected === true) {
                result.push((ele_item as any).dataValue);
            }
        });
        return result;
    }
    public override setValue(value: any): void {
        (this.ele_select.ele() as HTMLSelectElement).selectedIndex = -1;// 先清空选中状态
        if (Array.isArray(value)) {
            this.items.forEach(ele_item => {
                if (value.indexOf((ele_item as any).dataValue) >= 0) {
                    (ele_item as HTMLOptionElement).selected = true;
                }
            });
        } else if (value === DEFAULT) {
        } else {
            this.items.forEach(ele_item => {
                if (value === (ele_item as any).dataValue) {
                    (ele_item as HTMLOptionElement).selected = true;
                }
            });
        }
    }
}

interface _IK_ {
    // ========= 创建实例对象（通用） ========= //
    /**
     * 创建控件
     * @returns 控件实例对象
     */
    select(): KHTMLElement;

    /**
     * 创建控件
     * @param options 控件参数
     * @returns 控件实例对象
     */
    select(options: Toptions_Pselect): KHTMLElement;

    // ========= 创建实例对象（数据值控件） ========= //
    /**
     * 创建控件
     * @param data 数据
     * @returns 控件实例对象
     */
    select(data: Array<Toptions_DATA$dataI>): KHTMLElement;
}
{
    K.select = (...args: Array<any>) => { return new Pselect(...args).ele; };
}
